/**
 * @description 专家领域-新增弹窗
 * @author 李艳
 */

import React, {Component} from 'react'
import {Form, Input, InputNumber,Modal} from 'antd';
import {checkInputCode} from "../../../commons/utils/CommonUtils";
const FormItem = Form.Item;

class ProfessionalDomainEditModal extends Component {
    constructor(props) {
        super(props);
        this.state = {
            modalVisible: false,
            confirmLoading: false,
            code:"",
            name:""
        }
    }

    handleClose = () => {
        this.props.form.resetFields();
    };

    componentDidMount() {
        this.props.onRef(this);

    }
    render() {
        const formItemLayout = {
            labelCol: {
                span: 7
            },
            wrapperCol: {
                span: 14
            },
        };

        const {confirmLoading, modalVisible, handleOk, handleCancel, defaultValue,isAddRoot} = this.props;
        const {getFieldDecorator} = this.props.form;
        let title = "新增节点";
        let FormValue=defaultValue;
        if (isAddRoot){
            title="新增根节点";
            FormValue={}
        }
        return (
            <div>
                <Modal title={title}
                       visible={modalVisible}
                       onOk={handleOk}
                       onCancel={handleCancel}
                       width={500}
                       afterClose={this.handleClose}
                       confirmLoading={confirmLoading}
                       maskClosable={false}
                >
                    <Form>
                      {!isAddRoot&&<FormItem
                            {...formItemLayout}
                            label="父节点">
                            {getFieldDecorator('parentName', {
                                initialValue: defaultValue.name ?  defaultValue.name: "",
                            })(
                                <Input disabled/>
                            )}
                        </FormItem>}
                        <FormItem
                            {...formItemLayout}

                            label="代码">
                            {getFieldDecorator('code', {
                                rules: [{required: true, message: '请填写代码!'},{max:30,message:'长度不超过30字符！'},checkInputCode()]
                            })(
                                <Input/>
                            )}
                        </FormItem>
                        <FormItem
                            {...formItemLayout}
                            label="名称">
                            {getFieldDecorator('name', {
                                rules: [{required: true, message: '请填写名称!'},{max:50,message:'长度不超过50字符！'}]
                            })(
                                <Input />
                            )}
                        </FormItem>

                        <FormItem
                            {...formItemLayout}
                            label="排序">
                            {getFieldDecorator('rank', {
                              initialValue:0,
                                rules: [{required: true, message: '请填写排序!'}]
                            })(
                                <InputNumber precision={0} min={0} max={999999999} style={{width:"100%"}}/>
                            )}
                        </FormItem>
                        <FormItem
                            {...formItemLayout}
                            style={{display:'none'}}
                                 label="parentId">
                            {getFieldDecorator('parentId', {
                                initialValue: FormValue.id ?  FormValue.id: null,
                            })(
                                <Input/>
                            )}
                        </FormItem>
                    </Form>
                </Modal>
            </div>
        );
    }
}

ProfessionalDomainEditModal = Form.create()(ProfessionalDomainEditModal);
export default ProfessionalDomainEditModal;
